import requests
from bs4 import BeautifulSoup
class pcScrawler():
    def __init__(self):
        self.headers={
            "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.62"
        }
    def getTargetText(self, url,selector):
        codes=requests.get(url,headers=self.headers).text
        bs = BeautifulSoup(codes, 'html.parser')
        return [item.text for item in bs.select(selector=selector)]
    def getTargetImg(self,imgurl):
        imgc=requests.get(imgurl).content
        with open("tp1.jpg",'wb') as f:
            f.write(imgc)

if __name__=="__main__":
    url="https://new.qq.com/rain/a/20230404A01OPA00"
    s=pcScrawler()
    imgurl="https://inews.gtimg.com/om_bt/OChqOBz6-Sof1GiqyReet5JoLZR-uRFacUxKOLCqajPbsAA/1000"
    print(s.getTargetImg(imgurl))